
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import { ElMessage } from 'element-plus'
const routes: Array<RouteRecordRaw> = [

  {
    path: '/',
    redirect: "/login"
  },
  {
    path: '/login',
    name: 'login',

    component: () => import('../views/Login/index.vue')
  },
  {
    path: '/home',
    name: 'home',

    component: () => import('../views/HomeView/index.vue'),
    children: [
      {
        path: '/echarts',
        name: 'echarts',
        component: () => import('../views/HomeView/EchartsView.vue'),
        meta: {
          title: "数据展示"
        }
      },
      {
        path: '/permissionlist',
        name: 'permissionlist',
        component: () => import('../views/HomeView/PermissionList.vue'),
        meta: {
          title: "权限列表"
        }
      },
      {
        path: "/user",
        name: "user",
        component: () => import("../views/HomeView/UserOne.vue"),
        redirect: "/userlist",
        meta: {
          title: "住户信息"
        },
        children: [
          {
            path: '/userlist',
            name: 'userlist',
            component: () => import('../views/HomeView/UserList.vue'),
            meta: {
              classifyTitle: "用户信息",//分类标题
              title: "住户列表"
            }
          },
          {
            path: '/userupdate',
            name: 'userupdate',
            component: () => import('../views/HomeView/UserUpdate.vue'),
            meta: {
              classifyTitle: "用户信息",//分类标题
              title: "住户信息修改"
            }
          },
        ]
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})
//登陆拦截
router.beforeEach((to, from, next) => {
  console.log(to);
  if (to.path != '/login') {
    if (!localStorage.getItem('user')) {
      ElMessage({
        type: 'warning',
        message: '请先登陆！',
      })
      next('/login')
    }
  }
  next()
})

export default router
